<?php

class DefaultApp extends MallbaseApp
{
    function index()
    {
		$cache_id = "cache_index";

		//横幅广告调用		
		$adver_list = $this->_get_flash_adver('27');
		$this->assign('adver_list', $adver_list);
		$this->assign('new_list', $this->_get_article());//调出新闻公告
		$this->assign('now_current', "0");
		
		$this->import_resource(array( 'script' => 'res:js/about_FlexSlider.js' ));
		$this->display('about.index.html');
    }

	//调出频道的切换广告图片
	function _get_flash_adver($flash_id)
	{
		$this->adver_mod =& m('adver');
		$adver_list = $this->adver_mod->_get_adver_list($flash_id);
		$adver_list[$flash_id]['ad_img_name'] = unserialize($adver_list[$flash_id]['ad_img_name']);
		$adver_list[$flash_id]['ad_link'] = unserialize($adver_list[$flash_id]['ad_link']);
		$adver_list[$flash_id]['ad_img'] = unserialize($adver_list[$flash_id]['ad_img']);		
		$adver_list['flash']=array();$i=1;
		foreach($adver_list[$flash_id]['ad_img'] as $key => $var) 
		{
			$adver_list['flash'][$i]['ad_img_name'] = $adver_list[$flash_id]['ad_img_name'][$key];
			$adver_list['flash'][$i]['ad_link'] = $adver_list[$flash_id]['ad_link'][$key];
			$adver_list['flash'][$i]['ad_img'] = $var;
			$i++;
		}
		return $adver_list['flash'];
	}
	//获取新闻文章
    function _get_article($type='')
    {
        //缓存数据调用
		$cache_server =& cache_server();		
		$key = 'article_get_index';
        $articles = $cache_server->get($key);
        if ($articles === false)
        {		
			$_article_mod = &m('article');
			$articles = $_article_mod->find(array(
				'conditions'  => 'if_show=1 AND store_id=0 AND code = "" AND cate_id=2',
				'fields'     => 'article_id,title,cate_id,link,add_time',
				'limit'   => 6,
				'order'   => "add_time DESC,sort_order ASC",
			)); //找出所有符合条件的文章
			
			$cache_server->set($key, $articles, 1800);//半个小时更新一次
		}
        return $articles;
    }
		
	/************生成首页静态页面***************/

	/* 判断静态页面缓存文件是否存在  by liangcaijian */
	function is_cached_html($filename, $cache_id = '')
	{
	    $cachename = basename($filename, strrchr($filename, '.')) . '_' . $cache_id;
		$cache_dir    = ROOT_PATH . "/temp/caches_html/default/" . $cachename . '.php';
		if ( is_file($cache_dir) )
		{
			return true;
		}else{
			return false;
		}
	}
}
?>